const tools=require('../utils/tools')
const isSignin=async function(req,res,next){
    res.set('Content-Type', 'application/json; charset=utf-8')
    let token=req.get('X-Access-Token')
    console.log(token);
    
  if(token){
    if(req.path==='/isSignin'){
    res.render("success",{
      data: JSON.stringify({
      username:req.session.username
     })
  })
}else{
  let decode=await tools.verifyToken(token)
  if(decode){
      next()
  }else{
    res.render("fail",{
      data: JSON.stringify({
       message:'token验证失败'
     })
  })
  }

}
  }else{
    res.render("fail",{
      data: JSON.stringify({
       message:'没有权限'
     })
  })
  }
  }

  module.exports=isSignin